// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed class MlPreviewDataFrameAnalyticsRequestParameters : RequestParameters<MlPreviewDataFrameAnalyticsRequestParameters>
	{
	}

	public sealed partial class MlPreviewDataFrameAnalyticsRequest : PlainRequestBase<MlPreviewDataFrameAnalyticsRequestParameters>
	{
		public MlPreviewDataFrameAnalyticsRequest()
		{
		}

		public MlPreviewDataFrameAnalyticsRequest(Elastic.Clients.Elasticsearch.Id? id) : base(r => r.Optional("id", id))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPreviewDataFrameAnalytics;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		[JsonInclude]
		[JsonPropertyName("config")]
		public Elastic.Clients.Elasticsearch.Ml.DataframePreviewConfig? Config { get; set; }
	}

	public sealed partial class MlPreviewDataFrameAnalyticsRequestDescriptor<TDocument> : RequestDescriptorBase<MlPreviewDataFrameAnalyticsRequestDescriptor<TDocument>, MlPreviewDataFrameAnalyticsRequestParameters>
	{
		internal MlPreviewDataFrameAnalyticsRequestDescriptor(Action<MlPreviewDataFrameAnalyticsRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public MlPreviewDataFrameAnalyticsRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPreviewDataFrameAnalytics;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public MlPreviewDataFrameAnalyticsRequestDescriptor<TDocument> Id(Elastic.Clients.Elasticsearch.Id? id)
		{
			RouteValues.Optional("id", id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.Ml.DataframePreviewConfig? ConfigValue { get; set; }

		private DataframePreviewConfigDescriptor<TDocument> ConfigDescriptor { get; set; }

		private Action<DataframePreviewConfigDescriptor<TDocument>> ConfigDescriptorAction { get; set; }

		public MlPreviewDataFrameAnalyticsRequestDescriptor<TDocument> Config(Elastic.Clients.Elasticsearch.Ml.DataframePreviewConfig? config)
		{
			ConfigDescriptor = null;
			ConfigDescriptorAction = null;
			ConfigValue = config;
			return Self;
		}

		public MlPreviewDataFrameAnalyticsRequestDescriptor<TDocument> Config(DataframePreviewConfigDescriptor<TDocument> descriptor)
		{
			ConfigValue = null;
			ConfigDescriptorAction = null;
			ConfigDescriptor = descriptor;
			return Self;
		}

		public MlPreviewDataFrameAnalyticsRequestDescriptor<TDocument> Config(Action<DataframePreviewConfigDescriptor<TDocument>> configure)
		{
			ConfigValue = null;
			ConfigDescriptor = null;
			ConfigDescriptorAction = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (ConfigDescriptor is not null)
			{
				writer.WritePropertyName("config");
				JsonSerializer.Serialize(writer, ConfigDescriptor, options);
			}
			else if (ConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("config");
				JsonSerializer.Serialize(writer, new DataframePreviewConfigDescriptor<TDocument>(ConfigDescriptorAction), options);
			}
			else if (ConfigValue is not null)
			{
				writer.WritePropertyName("config");
				JsonSerializer.Serialize(writer, ConfigValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class MlPreviewDataFrameAnalyticsRequestDescriptor : RequestDescriptorBase<MlPreviewDataFrameAnalyticsRequestDescriptor, MlPreviewDataFrameAnalyticsRequestParameters>
	{
		internal MlPreviewDataFrameAnalyticsRequestDescriptor(Action<MlPreviewDataFrameAnalyticsRequestDescriptor> configure) => configure.Invoke(this);
		public MlPreviewDataFrameAnalyticsRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPreviewDataFrameAnalytics;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public MlPreviewDataFrameAnalyticsRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id? id)
		{
			RouteValues.Optional("id", id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.Ml.DataframePreviewConfig? ConfigValue { get; set; }

		private DataframePreviewConfigDescriptor ConfigDescriptor { get; set; }

		private Action<DataframePreviewConfigDescriptor> ConfigDescriptorAction { get; set; }

		public MlPreviewDataFrameAnalyticsRequestDescriptor Config(Elastic.Clients.Elasticsearch.Ml.DataframePreviewConfig? config)
		{
			ConfigDescriptor = null;
			ConfigDescriptorAction = null;
			ConfigValue = config;
			return Self;
		}

		public MlPreviewDataFrameAnalyticsRequestDescriptor Config(DataframePreviewConfigDescriptor descriptor)
		{
			ConfigValue = null;
			ConfigDescriptorAction = null;
			ConfigDescriptor = descriptor;
			return Self;
		}

		public MlPreviewDataFrameAnalyticsRequestDescriptor Config(Action<DataframePreviewConfigDescriptor> configure)
		{
			ConfigValue = null;
			ConfigDescriptor = null;
			ConfigDescriptorAction = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (ConfigDescriptor is not null)
			{
				writer.WritePropertyName("config");
				JsonSerializer.Serialize(writer, ConfigDescriptor, options);
			}
			else if (ConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("config");
				JsonSerializer.Serialize(writer, new DataframePreviewConfigDescriptor(ConfigDescriptorAction), options);
			}
			else if (ConfigValue is not null)
			{
				writer.WritePropertyName("config");
				JsonSerializer.Serialize(writer, ConfigValue, options);
			}

			writer.WriteEndObject();
		}
	}
}